//
//  MyDataTableViewController.m
//  1243
//
//  Created by 袖手旁觀 on 16/4/7.
//  Copyright © 2016年 1243. All rights reserved.
//

#import "MyDataTableViewController.h"
//#import "MyDataTableViewCell.h"
#import "NetWorkTools.h"
#import "MainInfoTableViewCell.h"

@interface MyDataTableViewController ()<UIAlertViewDelegate,UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong)NSDictionary *params;
@property (nonatomic, strong)UITableView    *tableView;
@end

@implementation MyDataTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.translucent = NO;
    self.view.backgroundColor = [UIColor colorWithRed:233/255.0 green:234/255.0 blue:238/255.0 alpha:1];
//    [self.tableView
//     registerNib:[UINib nibWithNibName:@"MyDataTableViewCell" bundle:nil] forCellReuseIdentifier:@"XingYingYangChangJian"];
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(15, 15, WIDTH- 30, 38 * 6+1) style:UITableViewStyleGrouped];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.rowHeight = 38.5;

    
    self.tableView.layer.borderWidth = 0.5;
    self.tableView.layer.borderColor = [[UIColor grayColor] CGColor];
    self.tableView.scrollEnabled = NO;
    
    [self.view addSubview:self.tableView];
    [self loadUserData];
    
    [self.tableView registerClass:[MainInfoTableViewCell class] forCellReuseIdentifier:@"CELL"];
    
    
    self.title = @"我的信息";
}



#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 6;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.01;
}
- (void)tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view forSection:(NSInteger)section {
    view.tintColor = [UIColor clearColor];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    MainInfoTableViewCell *mainCell = [tableView dequeueReusableCellWithIdentifier:@"CELL" forIndexPath:indexPath];
    
    if (indexPath.row == 0) {
        mainCell.titleLB.text = @"姓名:";
        mainCell.detailLB.text = self.params[@"RealName"];
    }else if (indexPath.row == 1){
        mainCell.titleLB.text = @"创建时间:";
        mainCell.detailLB.text = [self.params[@"CreateTime"] stringByReplacingOccurrencesOfString:@"T" withString:@" "];
    }else if (indexPath.row == 2){
        mainCell.titleLB.text = @"开户行:";
        mainCell.detailLB.text = self.params[@"WW"];
    }else if (indexPath.row == 3){
        mainCell.titleLB.text = @"Email:";
        mainCell.detailLB.text = self.params[@"Email"];
    }else if (indexPath.row == 4){
        mainCell.titleLB.text = @"电话:";
        mainCell.detailLB.text = self.params[@"Mobile"];
    }else if (indexPath.row == 5){
        mainCell.titleLB.text = @"生日:";
        mainCell.detailLB.text = [self.params[@"Birthday"] stringByReplacingOccurrencesOfString:@"T" withString:@" "];
    }
    
    
        mainCell.selectionStyle = UITableViewCellSelectionStyleNone;

    
    return mainCell;
    
//    if (self.params.count) {
//        MyDataTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"xingYingYangChangJian" ];
//        
//        if (cell == nil) {
//            cell = [[[NSBundle mainBundle] loadNibNamed:@"MyDataTableViewCell" owner:nil options:nil] lastObject];
//            
//            cell.selectionStyle = UITableViewCellSelectionStyleNone;
//        }
//        NSString *strUrl = [self.params[@"Birthday"] stringByReplacingOccurrencesOfString:@"T" withString:@" "];
//        cell.nameLabel.text = [NSString stringWithFormat:@"姓名:%@", self.params[@"RealName"]];
//        cell.titleLabel.text = [NSString stringWithFormat:@"开户行:%@", self.params[@"WW"]];
//          cell.timeLabel.text =   [NSString stringWithFormat:@"创建时间:%@", [self.params[@"CreateTime"] stringByReplacingOccurrencesOfString:@"T" withString:@" "]];
//          cell.email.text =    [NSString stringWithFormat:@"eMail:%@", self.params[@"Email"]];
//          cell.phone.text =[NSString stringWithFormat:@"电话:%@", self.params[@"Mobile"]];
//        cell.birthDay.text =[NSString stringWithFormat:@"生日:%@", strUrl];
//        return cell;
//    } else {
//        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
//        
//        if (cell == nil) {
//            cell = [[UITableViewCell alloc] init];
//            
//            cell.selectionStyle = UITableViewCellSelectionStyleNone;
//        }
//        return cell;
//        
//    }

    
}

- (void)loadUserData {
    NSDictionary *dict = @{
                           @"UserNumber":[ReadLoginData readLoginData][@"Number"]
                           };
    
    [[NetWorkTools sharedNetWorkTools] objectWithURLDict:dict AndMenthodName:@"INFORMATHIONLISTQUEY" completeBlock:^(id object) {
        
        NSLog(@"%@",object);
        
        if ([[object objectForKey:@"Id"] intValue] == 0) {
            [self.tableView reloadData];
        } else {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:[object objectForKey:@"Message"] delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
            alert.tag = 10001;
            [alert show];
        }
        
        NSString *string = [object objectForKey:@"BackData"];
        
        self.params = [NetWorkTools dictionaryWithJsonString:string];
        [self.tableView reloadData];
    }];

}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (alertView.tag == 10001) {
        [self.navigationController popViewControllerAnimated:YES];
    }
}

@end
